package zcw.com.lib_leet_code;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 朱城委 on 2021/11/25.<br><br>
 *
 * 中等：格雷编码
 */
public class Topic89 {

    public static void main(String[] args) {
        Topic89 instance = new Topic89();

        System.out.println(instance.grayCode(1));
        System.out.println(instance.grayCode(2));
        System.out.println(instance.grayCode(3));
    }

    public List<Integer> grayCode(int n) {
        List<Integer> list = new ArrayList<>();

        for(int i = 0; i < Math.pow(2, n); i++) {
            list.add(i ^ (i >> 1));
        }

        return list;
    }
}
